Skip to content

feat(spring-jakarta): [Queue Instrumentation 3] Add Kafka producer instrumentation#5254

Merged
adinauer merged 4 commits intofeat/queue-instrumentationfrom
feat/queue-instrumentation-producer
Apr 29, 2026
Merged

feat(spring-jakarta): [Queue Instrumentation 3] Add Kafka producer instrumentation#5254
adinauer merged 4 commits intofeat/queue-instrumentationfrom
feat/queue-instrumentation-producer

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Apr 1, 2026

PR Stack (Queue Instrumentation)


📜 Description

Add Kafka producer instrumentation to sentry-spring-jakarta:

  • SentryKafkaProducerWrapper — overrides doSend to create queue.publish spans for all KafkaTemplate send operations. Injects sentry-trace, baggage, and sentry-task-enqueued-time headers for distributed tracing and receive latency calculation.
  • SentryKafkaProducerBeanPostProcessor — automatically wraps KafkaTemplate beans.

💡 Motivation and Context

Producer-side instrumentation is needed to create publish spans and inject trace propagation headers into Kafka messages.

💚 How did you test it?

Unit tests for SentryKafkaProducerWrapper and SentryKafkaProducerBeanPostProcessor.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

Add SentryKafkaProducerWrapper that overrides doSend to create
queue.publish spans for all KafkaTemplate send operations. Injects
sentry-trace, baggage, and sentry-task-enqueued-time headers for
distributed tracing and receive latency calculation.

Add SentryKafkaProducerBeanPostProcessor to automatically wrap
KafkaTemplate beans.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (core) [Queue Instrumentation 1] Add enableQueueTracing option and messaging span data conventions by adinauer in #5250
  • (samples) [Queue Instrumentation 2] Add Kafka to Spring Boot 3 sample app by adinauer in #5253
  • (spring-jakarta) [Queue Instrumentation 3] Add Kafka producer instrumentation by adinauer in #5254
  • Add strict trace continuation support by giortzisg in #5136
  • Sync file attachments to native by bitsandfoxes in #5211

Internal Changes 🔧

Deps

  • Bump requests from 2.32.4 to 2.33.0 in the uv group across 1 directory by dependabot in #5237
  • Bump github/codeql-action from 4.32.6 to 4.35.1 by dependabot in #5243

Other

  • Add THIRD_PARTY_NOTICES.md for vendored third-party code by markushi in #5186

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- [Queue Instrumentation 3] Add Kafka producer instrumentation ([#5254](https://github.com/getsentry/sentry-java/pull/5254))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against fdb3a03

@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 1, 2026

Sentry Build Distribution

App Name App ID Version Configuration Install Page
SDK Size io.sentry.tests.size 8.37.1 (1) release Install Build

Configure sentry-android build distribution settings

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 396.90 ms 421.90 ms 25.00 ms
Size 0 B 0 B 0 B

Previous results on branch: feat/queue-instrumentation-producer

Startup times

Revision Plain With Sentry Diff
6d877aa 308.23 ms 348.66 ms 40.43 ms
d439efd 323.43 ms 384.17 ms 60.73 ms

App size

Revision Plain With Sentry Diff
6d877aa 0 B 0 B 0 B
d439efd 0 B 0 B 0 B

adinauer and others added 2 commits April 9, 2026 13:14
…oducerInterceptor

Replace the KafkaTemplate subclass approach with a Kafka-native
ProducerInterceptor. The BeanPostProcessor now sets the interceptor
on the existing KafkaTemplate instead of replacing the bean, which
preserves any custom configuration on the template.

Existing customer interceptors are composed using Spring's
CompositeProducerInterceptor. If reflection fails to read the
existing interceptor, a warning is logged.

Co-Authored-By: Claude <noreply@anthropic.com>
TransactionContext constructor requires ScopesAdapter.getOptions() to
be non-null for thread checker access. Add initForTest/close to
ensure Sentry is properly initialized during tests.

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit fdb3a03. Configure here.

Base automatically changed from feat/queue-instrumentation-sample to feat/queue-instrumentation April 29, 2026 13:12
@adinauer adinauer merged commit 9830c0c into feat/queue-instrumentation Apr 29, 2026
112 of 113 checks passed
@adinauer adinauer deleted the feat/queue-instrumentation-producer branch April 29, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants